#--
# Copyright (c) 2007 Mathew Abonyi
# Please read LICENSE document for more information.
#++

module Retrospectiva
  module Extension
    module SCMTicketUpdate

      # The Update class mediates between the raw log message and the dirty
      # business of parsing it into useful data. It then handles the creation
      # of one or more TicketReference objects from that data.
      class Update

        attr_accessor :author, :log, :references

        def initialize(author, log)
          self.author = author
          self.log = log
          self.references = []
          Parser.parse_log(log) do |hash|
            self.references << TicketReference.new(hash.merge(:user => author))
          end
        end

        def each_reference
          references.each { |ref| yield ref }
        end

      end

    end
  end
end